#include <iostream>

using namespace std;

int arr[10], vis[10] = {0};

void output(int n) {
  for (int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    cout << arr[i];
  }
  cout << endl;
  return;
}

void f(int i, int n) {
  // cout << "i = " << i  << " n = " << n << endl;
  if (i == n) {
    output(n);
    // cout << "return\n" << endl;
    return;
  }
  for (int k = 1; k <= n; k++) {
    // cout << "k = " << k << " i = " << i << endl;
    if (vis[k]){
      // cout << "continue\n" << endl;
      continue;
    }
    arr[i] = k;
    vis[k] = 1;
    // cout << k << " is vis" << endl;
    f(i + 1, n);
    vis[k] = 0;
    // cout << k << " is not vis" << endl;
  }
  return;
}

int main() {
  int n;
  cin >> n;
  f(0, n);
  return 0;
}
